package com.nwpusp.display.views.components;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;

import com.example.petssports.R;
import com.nwpusp.display.GlobalVar;

public class Podium extends View{
	public Bitmap podiumBitmap;
	public Bitmap header;
	public float x;
	public float y;
	public float scale;
	public float width;
	public float height;
	public int index;
	
	public Podium(Context view,float scale,int winnerNum){
		super(view);
		this.scale = scale;
		this.index = winnerNum;
		getBitmapSource();
		podiumBitmap = GlobalVar.VerticalScale(podiumBitmap,scale);
		header = GlobalVar.VerticalScale(header,scale);
		podiumBitmap = CombinationBitmap(header,podiumBitmap);
		width = podiumBitmap.getWidth();
		height = podiumBitmap.getHeight();
	}
	
	public void setLocation(float x ,float y){
		this.x = x;
		this.y = y;
	}
	
	private void getBitmapSource(){
		switch(index){
			case 1:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header1);
				break;
			}
			case 2:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header2);
				break;
			}
			case 3:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header3);
				break;
			}
			case 4:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header4);
				break;
			}
			case 5:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header5);
				break;
			}
			case 6:{
				header = BitmapFactory.decodeResource(getResources(), R.drawable.header6);
				break;
			}
			default:break;
		}
		podiumBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.podium);
	}
	
	public Bitmap draw(){
		return podiumBitmap;
	}
	
	public static Bitmap CombinationBitmap(Bitmap SourceBitmap1,Bitmap SourceBitmap2){
		 int bgWidth;
		 int bgHeight;
		 int bg1Width = SourceBitmap1.getWidth(); 
		 int bg2Width = SourceBitmap2.getWidth(); 
		 if(bg1Width>bg2Width)
			 bgWidth = bg1Width;
		 else 
			 bgWidth = bg2Width;
		 int bgHeight1 = SourceBitmap1.getHeight();
		 int bgHeight2 = SourceBitmap2.getHeight();
        bgHeight = bgHeight1 + bgHeight2;   
        Bitmap newbmp = Bitmap.createBitmap(bgWidth, bgHeight, Bitmap.Config.ARGB_8888);  
        Canvas cv = new Canvas(newbmp);    
        cv.drawBitmap(SourceBitmap2, (bgWidth-bg2Width)/2, bgHeight1*(float)0.9, null);
        cv.drawBitmap(SourceBitmap1, (bgWidth-bg1Width)/2, 0, null); 
        cv.save(Canvas.ALL_SAVE_FLAG);  
        cv.restore();  
        return newbmp;   
	}

}
